package com.onlyphoto.onlymall.mvp.view.binder

import android.annotation.SuppressLint
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.bean.OrderFooterBean
import com.onlyphoto.onlymall.mvp.view.activity.OrderDetailsActivity

import me.drakeet.multitype.ItemViewBinder

/**
 * Created by gaochujia on 2019-07-01.
 */
class OrderListFooterBinder : ItemViewBinder<OrderFooterBean, OrderListFooterBinder.ViewHolder>() {


    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        val root = inflater.inflate(R.layout.item_order_footer, parent, false)
        return ViewHolder(root)
    }

    override fun onBindViewHolder(viewHolder: ViewHolder, bean: OrderFooterBean) {
        viewHolder.update(bean)
        viewHolder.details?.setOnClickListener{
            viewHolder.itemView.context.startActivity(Intent(viewHolder.itemView.context, OrderDetailsActivity::class.java)
                    .putExtra("orderId", bean.orderId))
        }
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        private var orderCount: TextView? = null
        private var orderAmount: TextView? = null
        var details: TextView? = null

        init {
            orderCount = itemView.findViewById(R.id.order_count)
            orderAmount = itemView.findViewById(R.id.order_amount)
            details = itemView.findViewById(R.id.details)
        }

        @SuppressLint("SetTextI18n")
        fun update(bean: OrderFooterBean) {
            orderCount?.text = "共${bean.count}件，合计："
            orderAmount?.text = "¥ ${bean.total_price}"
        }
    }
}
